package com.iweb.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iweb.mapper.GameMapper;
import com.iweb.model.Game;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Time :2022/8/15 14:01
 * Author : kriller
 * Project : steam-malls
 */
@Service
public class GameService {
    @Resource
    private GameMapper gameMapper;

    public List<Game> selectGames(Integer page) {
        PageHelper.startPage(page,10);

        List<Game> games = gameMapper.selectList();

        PageInfo<Game> info = new PageInfo<>(games);
        return info.getList();
    }
    public List<Game> selectGames() {
        List<Game> games = gameMapper.selectList();
        return games;
    }

    public List<Game> selectGamesByName(Integer page , String name) {
        PageHelper.startPage(page,10);

        List<Game> games = gameMapper.selectByName(name);

        PageInfo<Game> info = new PageInfo<>(games);
        return info.getList();
    }

    public List<Game> selectGameByTag(Integer page, String tagName) {
        PageHelper.startPage(page,10);

        List<Game> games = gameMapper.selectByTag(tagName);

        PageInfo<Game> info = new PageInfo<>(games);
        return info.getList();
    }

    public Game selectById(Integer gameID) {
        Game game = gameMapper.selectById(gameID);
        return game;
    }

    public void insertNewGame(Game game) {
        gameMapper.insertGame(game);
    }

    public void updateGame(Game game) {
        gameMapper.updateGame(game);
    }

    public void deleteGameByGameId(Integer gameId) {
        gameMapper.deleteGame(gameId);
    }

    public List<String> getGameTag(Integer gameId) {
        List<String> tags = gameMapper.selectGameTag(gameId);
        return tags;
    }
}
